package com.sa07.db.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.OracleDriver;

import com.sa07.db.DbConfig;
import com.sa07.db.DefaultSession;

/**
 * Oracle数据库会话对象
 * 
 * @author Long.shangbo
 * 
 *         2014-2-15 下午6:53:14
 */
public class OracleSession extends DefaultSession {

	private static String URL = null;

	public OracleSession(DbConfig dbConfig) {
		if (URL == null) {
			URL = String.format("jdbc:oracle:thin:%s/%s@%s:%d:%s",
					dbConfig.getDbUserName(), dbConfig.getDbUserPwd(),
					dbConfig.getDbIp(), dbConfig.getDbPort(),
					dbConfig.getDbName());
		}
	}

	@Override
	protected Connection createConnection() throws SQLException {
		DriverManager.registerDriver(new OracleDriver());
		Connection conn = DriverManager.getConnection(URL);
		conn.setAutoCommit(false);
		return conn;
	}

}
